package day_2022_12_to_3.year2023;

import java.util.HashMap;
import java.util.Map;

/**
 * @author haomin
 * @date 2023/02/01 22:49
 **/
public class Day2_1_Num2335 {
    class Solution {
        public String decodeMessage(String key, String message) {
            Map<Character, Character> map = new HashMap<>();
            int idx = 0;
            for (char c : key.toCharArray()) {
                if (c == ' ') {
                    continue;
                }
                if (map.size() == 26) {
                    break;
                }
                if (map.containsKey(c)) {
                    continue;
                }
                map.put(c, (char)('a' + idx));
                idx++;
            }
            StringBuilder sb = new StringBuilder();
            for (char c : message.toCharArray()) {
                if (c == ' ') {
                    sb.append(' ');
                    continue;
                }
                sb.append(map.get(c));
            }
            return sb.toString();
        }
    }
}